/**
 * Created by LinJe on 2015/9/22.
 * 全局ui：登陆提示 弹窗
 */
(function( $, window ) {

    window.globalLayer = window.globalLayer || {};


    /**
     * 调用实例
     * window.globalLayer.openPublish({'callBack':function() {
            console.log('登陆提示窗已关闭');
       }});
     * @param settings
     */
    window.globalLayer.openPublish = function( settings ) {

        var publishArgs;

        //如果是第一次调用，加载弹窗所需html和js变量
        if ( !this.publishArgs ) {
            $('body').append('\
                <div class="layer_publish">\
                    <div class="popup-bg"></div>\
                    <div class="popup release-goods">\
                        <div class="content">\
                            <div class="title clearfix"><div class="btn"><span class="close" title="关闭"></span></div></div>\
                            <div class="text-con"><p>分享成功！</p></div>\
                            <div class="button"><button type="button" class="button-2">关闭</button><button type="button" class="button-1"></button></div>\
                        </div>\
                    </div>\
                </div>\
            ');

            publishArgs = this.publishArgs = {};
            publishArgs.$publishWrap = $('.layer_publish');
            publishArgs.$colse = publishArgs.$publishWrap.find('.title .btn');
            publishArgs.$cancle = publishArgs.$publishWrap.find('.button .button-2');
            publishArgs.$linkButton = publishArgs.$publishWrap.find('.button .button-1');
            publishArgs.$content = publishArgs.$publishWrap.find('.text-con p');
            publishArgs.href = '';

            //点击取消或者X 关闭弹窗
            publishArgs.$colse.on('click', function() { window.globalLayer.closePublish(publishArgs.callBack) });
            publishArgs.$cancle.on('click', function() { window.globalLayer.closePublish(publishArgs.callBack) });

            //点击 前往讨论页 或 去看看
            publishArgs.$linkButton.on('click', function() {
                location.href = publishArgs.href;
            });
        }

        publishArgs = this.publishArgs;
        $.extend(publishArgs, settings);

        //文案赋值
        publishArgs.$content.text(publishArgs.content);
        publishArgs.$linkButton.text(publishArgs.linkText);

        publishArgs.href = publishArgs.url;

        publishArgs.$publishWrap.css({'opacity':'0', 'display':'block'}).stop().animate({ 'opacity': 1 });
    };


    window.globalLayer.closePublish = function( callBack ) {

        this.publishArgs.$publishWrap.stop().animate({ 'opacity': 0 }, 500, '', function() {
            $(this).hide();
            callBack && callBack();
        });

    };

})( jQuery, window );